using DG.Tweening;
using DG.Tweening.Core;
using DG.Tweening.Plugins.Options;
using NL.UIEffects;
using UnityEngine.UI;

namespace NL.SpriteAnimation
{
    public class OnOffUIDissolve : OnOffAction
    {
        public float Factor = 0;

        UIDissolve uiGraphic;
        float _OldFactor;
        // Start is called before the first frame update
        void Awake()
        {
            uiGraphic = GetComponentInChildren<UIDissolve>();

            _OldFactor = uiGraphic != null ? uiGraphic.effectFactor : 0;
        }
        Tweener _Animer;
        protected override void _On()
        {
            if (uiGraphic == null) return;

            if (_Animer != null && _Animer.IsPlaying()) _Animer.Kill();
            _Animer = uiGraphic.DOFactor(Factor, Duration).SetDelay(Delay).SetEase(AnimEase);
        }
        protected override void _Off()
        {
            if (uiGraphic == null) return;

            if (_Animer != null && _Animer.IsPlaying()) _Animer.Kill();
            _Animer = uiGraphic.DOFactor(_OldFactor, Duration * 0.5f);
        }

    }


}

